from django.shortcuts import render
from .serializer import ComplaintsSerializer
from rest_framework import viewsets
from .models import Complaints
from .serializer import ComplaintsSerializer, ComplaintsDetailSerializer
# Create your views here.

class ComplaintViewSet(viewsets.ModelViewSet):
    serializer_class = ComplaintsSerializer
    def get_queryset(self):
        queryset = Complaints.objects.all()
        params = self.request.query_params
        if params:
            filters = {}
            for key, value in params.items():
                filters[key] = value
            queryset = queryset.filter(**filters)
        return queryset
    
class ComplaintDetailViewSet(viewsets.ModelViewSet):
    serializer_class = ComplaintsDetailSerializer
    def get_queryset(self):
        queryset = Complaints.objects.all()
        params = self.request.query_params
        if params:
            filters = {}
            for key, value in params.items():
                filters[key] = value
            queryset = queryset.filter(**filters)
        return queryset
        
